syntax = "proto3";

package spqr;

option go_package = "spqr/proto";
  
service KeyRangeService {
  rpc ListKeyRange (ListKeyRangeRequest) returns (KeyRangeReply) {}
  rpc LockKeyRange (LockKeyRangeRequest) returns (ModifyReply) {}
  rpc AddKeyRange(AddKeyRangeRequest) returns (ModifyReply) {}
  rpc DropKeyRange(DropKeyRangeRequest) returns (ModifyReply) {}
  rpc DropAllKeyRanges(DropAllKeyRangesRequest) returns (DropAllKeyRangesResponse) {}
  rpc UnlockKeyRange (UnlockKeyRangeRequest) returns (ModifyReply) {}
  rpc SplitKeyRange (SplitKeyRangeRequest) returns (ModifyReply) {}
  rpc MergeKeyRange (MergeKeyRangeRequest) returns (ModifyReply) {}
  rpc MoveKeyRange (MoveKeyRangeRequest) returns (ModifyReply) {}
  rpc ResolveKeyRange (ResolveKeyRangeRequest) returns (ResolveKeyRangeReply) {}
}

enum KeyRangeStatus {
  LOCKED = 0;
  AVAILABLE = 1;
}

message KeyRange {
  string lower_bound = 1;
  string upper_bound = 2;
}

// key range info is mapped to shard
message KeyRangeInfo {
  KeyRange key_range = 1;
  string krid = 2;
  string shardId = 3;
}

message ListKeyRangeRequest {
}

message AddKeyRangeRequest {
  KeyRangeInfo key_range_info = 1;
}

message SplitKeyRangeRequest {
  KeyRangeInfo key_range_info = 1;
  bytes bound = 2;
  string source_id = 3;
}

message MergeKeyRangeRequest {
  bytes bound = 1;
}

message MoveKeyRangeRequest {
  KeyRangeInfo key_range = 1;
  string toShardId = 2;
}

message DropKeyRangeRequest {
  repeated string id = 1;
}

message DropAllKeyRangesRequest {
}

message DropAllKeyRangesResponse {
  repeated KeyRangeInfo key_range = 1;
}

message LockKeyRangeRequest {
  repeated string id = 1;
}

message UnlockKeyRangeRequest {
  repeated string id = 1;
}

message KeyRangeReply {
  repeated KeyRangeInfo key_ranges_info = 1;
}

message ModifyReply {
  string operation_id = 1;
}

message ResolveKeyRangeRequest {
  string bound = 1;
}

message ResolveKeyRangeReply {
  repeated string key_range_d = 1;
}
